﻿#pragma once
#include"hash.h"


namespace tmt
{

	template<class K, class V, class Hash = HashFunc<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K,V>& kv)
			{
				return kv.first;
			}
		};
		typedef typename HashBucket::HashTable<K,pair<K,V>,Hash,MapKeyOfT>::iterator iterator;
	public:
		bool insert(const pair<K,V>& kv)
		{
			return _HT.insert(kv);
		}
		iterator begin()
		{
			return _HT.begin();
		}
		iterator end()
		{
			return _HT.end();
		}
		V& operator[](const K& key)
		{
			pair<iterator,bool> ret = _HT.insert(make_pair(key,V()));
			return ret.first->second;
		}
	private:
		HashBucket::HashTable<K, pair<K,V>, Hash ,MapKeyOfT> _HT;
	};
	void testMap()
	{
		unordered_map<int, int> countMap;
		//string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜", "苹果", "香蕉", "苹果", "香蕉" };
		int arr[] = { 1,11,111,1111 };
		for (auto e : arr)
		{
			countMap[e]++;
		}

		for (auto& kv : countMap)
		{
			cout << kv.first << ":" << kv.second << endl;
		}
	}
}